from fastapi import WebSocket, APIRouter
import asyncio
import random

router = APIRouter()

@router.websocket("/realtime")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    while True:
        data = {
            "time": "2023-01-01T00:00:00",  # 替换为实际数据
            "price": round(100 + random.uniform(-2, 2), 2),
            "volume": random.randint(1000, 10000)
        }
        await websocket.send_json(data)
        await asyncio.sleep(1)
